package com.dotflat.training.controller;

import com.dotflat.training.service.XETApiService;
import com.matt.foundation.model.ErrorCode;
import com.tuo51.foudation.model.StatusResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

import static com.matt.foundation.constant.RequestConstant.TICKET;


/**

 * @author wangxuchuan

 * @date 2020/10/30

 */

@RestController
@Slf4j
@RequestMapping("/api/yz/live")
@Api(tags = "有赞教育 - 直播")
public class YZLiveController {

    @Autowired
    private XETApiService apiService;


    @GetMapping("/playurl")
    @ApiOperation(value = "直播h5跳转地址")
    public StatusResponse getLivePlayURL(@RequestHeader(TICKET) String ticket,
                                     String alias){
//        https://h5.youzan.com/wscvis/knowledge/index?kdt_id=99491309&page=livedetail&alias=1ykc0ney0yprhjp&qr=paidcontent_1ykc0ney0yprhjp&shopAutoEnter=1

        if (StringUtils.isEmpty(alias)) {
            return StatusResponse.error(ErrorCode.PARAM_CAN_NOT_BLANK, "alias不能为空");
        }

//        String formatter = "https://h5.youzan.com/wscvis/knowledge/index?kdt_id=%s&page=livedetail&alias=%s&qr=paidcontent_%s&shopAutoEnter=1";
//        String url = String.format(formatter, yzTokenService.getShopId(), alias, alias);
        return StatusResponse.success(alias);
    }


    @GetMapping("/list")
    @ApiOperation(value = "直播列表， 响应字段参见 https://doc.youzanyun.com/detail/API/0/321")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string")
    })
    public StatusResponse getLiveList(@RequestHeader(TICKET) String ticket,
                                      @RequestParam(required = false, defaultValue = "0")int pageNum,
                                      @RequestParam(required = false, defaultValue = "20")int pageSize,
                                      @RequestParam(required = false) String keyword){
//        Map result = xetApiService.getGoodsList()
//        return StatusResponse.success(new ArrayList<>());
        Map apiResult = apiService.getLiveList(pageNum, pageSize, keyword);
        return StatusResponse.success(apiResult);
    }

}
